﻿using System;
using System.Collections.Generic;
using System.Text;
using DDBuildTools.DataAccess.Components;
using Antlr.StringTemplate;
using Antlr.StringTemplate.Language;

namespace DDBuildTools
{
    public class DDBuildHtml:IBuildFile
    {
        public bool BuildFile(List<TableEntity> TableList, string DataBaseCode, string TemplateUrl, string SavePath)
        {
            bool rBool = false;

            string TemplateDir = AppDomain.CurrentDomain.BaseDirectory + Common.TemplateList[TemplateUrl];

            StringTemplateGroup group = new StringTemplateGroup("MyGroup", new LoadFileHtm(TemplateDir), typeof(DefaultTemplateLexer));
            StringTemplate IndexTemplate = group.GetInstanceOf("index");
            IndexTemplate.SetAttribute("DataBaseName", DataBaseCode);


            StringTemplate IndexLeft = group.GetInstanceOf("left");
            IndexLeft.SetAttribute("DataBaseName", DataBaseCode);
            IndexLeft.SetAttribute("TableEntity", TableList);


            StringTemplate IndexTable = group.GetInstanceOf("Table");
            IndexTable.SetAttribute("TableEntity", TableList);
            IndexTable.SetAttribute("DataBaseName", DataBaseCode);


            Common.CopyFolder(TemplateDir, SavePath);

            Common.WriteFile(IndexTemplate.ToString(), SavePath + @"\index.htm");
            Common.WriteFile(IndexLeft.ToString(), SavePath + @"\left.htm");
            Common.WriteFile(IndexTable.ToString(), SavePath + @"\Table.htm");

            return rBool;
        }
    }
}
